package com.jzg.jcptadmin.base;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.jzg.jcptadmin.Utils.MyToast;
import com.jzg.jcptadmin.app.AppContext;
import com.jzg.jcptadmin.app.AppManager;
import com.orhanobut.logger.Logger;
import com.pnikosis.materialishprogress.ProgressWheel;
import com.umeng.analytics.MobclickAgent;

import cn.pedant.SweetAlert.SweetAlertDialog;


public class BaseActivity extends FragmentActivity {
//    private ReactiveNetwork reactiveNetwork;
    private SweetAlertDialog pDialog;
    public AppContext appContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏标题栏
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            // Translucent status bar
            window.setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        AppManager.getAppManager().addActivity(this);
        appContext =AppContext.getContext();
//        JPushInterface.resumePush(getApplicationContext());
        Logger.e("当前activityName--"+getClass().getSimpleName());
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
//        JPushInterface.onResume(this);


    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
//        JPushInterface.stopPush(this);
//        connectivitySubscription.unsubscribe();
//        wifiSubscription.unsubscribe();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 结束Activity&从堆栈中移除
        AppManager.getAppManager().finishActivity(this);
    }

    public void showDialog() {
        if (pDialog != null && pDialog.isShowing()) {
            return;
        }
        pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
//        pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
        pDialog.getProgressHelper().setProgressWheel(new ProgressWheel(this));
//        pDialog.setTitleText("");
        pDialog.setCancelable(false);
        pDialog.show();
    }

    public void dismissDialog() {
        if (pDialog != null && pDialog.isShowing()) {
            pDialog.dismissWithAnimation();

        }
    }

    public SweetAlertDialog  getDialog(){
        return pDialog;
    }
//    public void dismissDialog1() {
//        if (pDialog != null && pDialog.isShowing()) {
//            pDialog.dismissWithAnimation();
//        }
//        finish();
//    }

    public void goBack(View v) {
        finish();
    }

    /**
     * 根据条件，比如状态、价格等，筛选数据
     */
    public void filter_date(int status, int position) {
        showDialog();
    }

    /**
     * 显示错误信息
     *
     * @param error 错误信息
     */
    public void showError(String error) {
        MyToast.showShort(error);
    }



}
